package blog.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import blog.entity.Tag;
import blog.service.TagService;

@Controller @RequestMapping("/tag")
public class TagController {
	@Resource
	private TagService tagService;
	
	/**
	 *标签管理页
	 */
	@RequestMapping("")
	public String index(ModelMap m) {
		List<Tag> tagList = tagService.listTag();
		m.put("tagList", tagList);
		return "Tag/tag-list";
	}
	
	/*
	 * 跳转标签添加页
	 */
	@RequestMapping(value = "/add", method = RequestMethod.POST) // 提交方式如果GET则转到文章发布页
	public String add(Tag tag) {
		tagService.add(tag);
		return "forward:/tag";
		
	}
	/**
	 * 删除标签
	 */
	@RequestMapping("/delete/{tagId}")
	public String delete(@PathVariable("tagId") Integer tagId)  {
		tagService.deleteTag(tagId);
		return "forward:/tag";
	}
}
